package org.gordonframework.site.forms.elements.skins {
	import org.gordonframework.core.graphics.GDraw;
	import org.gordonframework.site.forms.elements.GElement;
	import org.gordonframework.site.forms.elements.skins.GElementSkin;
	import org.gordonframework.site.views.GLabel;
	import org.gordonframework.site.views.GView;	

	/**
	 * @author eriarv
	 */
	public class GButtonSkin extends GElementSkin {
		
		private var background : GView;
		private var border : GView;
		
		public function GButtonSkin() {
			super();
			background = new GView();
			border = new GView();
			label = new GLabel();
			label.wordWrap = false;
			addChild( background );
			addChild( border );
			addChild( label );
			buttonMode = true;
			mouseChildren = false;
		}
		
		override public function update(element : GElement) : void {
			
			super.update(element);

			label.setDefaultTextFormat(textFormats.label);
			label.text = element.text;
			label.x = format.paddingX;
			label.y = format.paddingY;
			
			background.graphics.beginFill(format.background.color, format.background.alpha);
			GDraw.rect(background.graphics, label.right + format.paddingX, format.background.height);
			background.graphics.endFill();
			
			border.graphics.lineStyle( format.border.thickness, format.border.color, format.border.alpha );
			border.graphics.drawRect(0, 0, background.width, background.height);
			
		
		}
		
		
	}
}
